package com.esoon.controller;

import com.esoon.service.SoftPhoneCallService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @ClassName SoftPhoneCallController
 * @Description TODO
 * @Author 2020/9/29 23:01
 * @Version 1.0
 **/
@RestController
@RequestMapping("/v1/SoftPhoneCall")
public class SoftPhoneCallController {

    private static final Logger logger;

    static {
        logger = LoggerFactory.getLogger(SoftPhoneCallController.class);
    }
    @Resource
    private SoftPhoneCallService softPhoneCallService;

    @RequestMapping(value = "/selectAbandonPhone",method = RequestMethod.GET)
    public String selectAbandonPhone(@RequestParam String phone){
        //在程序进入到这里的时候创建一个时间对象，根据该时间点获取之前三十分钟的时间点。
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
        simpleDateFormat.applyPattern("yyyy-MM-dd HH:mm:ss");
        Calendar instance = Calendar.getInstance();
        String endTime = simpleDateFormat.format(instance.getTime());
        instance.add(Calendar.MINUTE,-30);
        String startTime = simpleDateFormat.format(instance.getTime());
        logger.info("invoking 30minute softPhoneCall abandonCall interface , the url = '/v1/SoftPhoneCall/selectAbandonPhone', the requestParam : phone = [{}], startDate is [{}] , endDate = [{}]" , phone , startTime ,endTime);
        return softPhoneCallService.selectAbandonPhone(startTime, endTime, phone);


    }

    //更改放弃类型，接口有变化 ，新儒传入4个参数，在代码中生成一些时间数据完整的插入的softphone_phone表中

    @RequestMapping(value = "/updateCLHangupByConnId",method = RequestMethod.GET)
    public String updateCLHangupByConnId(@RequestParam String connId){
        logger.info("invoking update callType interface , the url = '/v1/SoftPhoneCall/updateCLHangupByConnId', the requestParam : connId = [{}]",connId);
       return softPhoneCallService.updateCLHangupByConnId(connId);
    }
    /*
     * @Author Jack
     * @Description //TODO 插入排队呼损数据至softphone_call表中，默认通话类型为呼入，放弃类型为102，
     * @Date 10:35 2020/10/15
     * @Param
     * @return 插入成功时 返回0 插入失败时 返回500
     **/

    @RequestMapping(value = "/insert" ,method = RequestMethod.GET)
    public String insert(@RequestParam String connId,@RequestParam String ani,@RequestParam String dnis,@RequestParam String dept){
        logger.info("invoking insert abandonCall interface , the url = '/v1/SoftPhoneCall/insert', the requestParam :connId = [{}] , ani = [{}] , dnis = [{}] , dept = [{}]",connId , ani , dnis , dept);
        return softPhoneCallService.insert(connId, ani, dnis, dept);

    }
}
